﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web;
using System.Web.Mail;

namespace PRT
{
    public class MessageDelivery
    {
        public static string SendEmail(string to, string message, NameValueCollection customfields)
        {
            MailMessage objEmail = new MailMessage();

            objEmail.From = "messagecenter@bryan800.com";
            objEmail.Subject = "A message just arrived for you";
            objEmail.BodyFormat = MailFormat.Html;
            string body = "<html><body>";
            body += (message + "<br /><br />");
            foreach (string key in customfields.AllKeys)
                body += (key + ": " + customfields[key] + "<br /><br />");
            body += "</body></html>";
            objEmail.Body = body;
            objEmail.To = "rturner@lockardandwhite.com";
            SmtpMail.SmtpServer = "lockardandwhite.com";
            //SmtpMail.SmtpServer = "mail.bryan800.com";

            try
            {
                SmtpMail.Send(objEmail);
                return ("Your Email has been sent sucessfully - Thank You");
            }
            catch (Exception exc)
            {
                return ("Send failure: " + exc.ToString());
            }
        }

        private string removeFormatting(string s)
        {
            char[] arr = s.ToCharArray();
            int removed = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                if ((int)arr[i] > 57 || (int)arr[i] < 48)
                {
                    s.Remove(i - removed);
                    removed++;
                }
            }
            return arr.ToString();
        }
    }
}